package com.wlyuan.index.domain.source.valueobj;

import com.wlyuan.core.domain.valueobj.ContractNo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.lang.NonNull;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class Keywords implements Iterable<String> {
    private final Set<String> values = new HashSet<>();

    private boolean isNamedCity(String city) {
        return StringUtils.isNotEmpty(city) && !"市辖区".equals(city);
    }

    private void add(String keyword) {
        if (StringUtils.isEmpty(keyword)) {
            return;
        }
        values.add(keyword);
    }

    public void add(Consignee consignee) {
        if (null == consignee) {
            return;
        }
        this.add(consignee.getName());
    }

    public void add(Customer customer) {
        if (null == customer) {
            return;
        }
        this.add(customer.getName());
        this.add(customer.getHighName());
    }

    public void add(Address address) {
        if (null == address) {
            return;
        }

        if (isNamedCity(address.getCity())) {
            this.add(address.getCity());
        } else {
            this.add(address.getProvince());
        }
        this.add(address.getContactName());
    }

    public void add(ContractNo contractNo) {
        if (null == contractNo) {
            return;
        }
        this.add(contractNo.getValue());
    }

    @Override
    @NonNull
    public Iterator<String> iterator() {
        return this.values.iterator();
    }
}